/**
 * 
 */
package travibot.ui.gui.forms;

import org.eclipse.jface.resource.ImageRegistry;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.TabItem;
import org.eclipse.swt.SWT;

import travibot.engine.GameSessionFacade;
import travibot.engine.Session;
import travibot.engine.TaskQueue;
import travibot.model.Village;
import travibot.ui.UIFactory;
import travibot.ui.gui.StatusNotification;
import org.eclipse.swt.widgets.TabFolder;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
/**
 * @author tajzivit
 *
 */
@Deprecated
public class MainShell implements MainForm {

    private Shell sShell = null;  //  @jve:decl-index=0:visual-constraint="10,10"
    private CompositeForm cityList = null;
    private TabFolder centerTabFolder = null;  //  @jve:decl-index=0:visual-constraint="25,16"
    private StatusBar statusBar = null;
    private CompositeForm fields = null;
    private CompositeForm buildings = null;
    private CompositeForm tasks = null;
    private TabItem filedsTabItem = null;
    private TabItem buildingsTabItem = null;
    private TabItem tasksTabItem = null;
    
    
    public Shell getSShell() {
    
        return sShell;
    }

    /**
     * This method initializes sShell
     */
    public void createSShell(Display display) {

        GridLayout gridLayout = new GridLayout();
        gridLayout.numColumns = 2;  // Generated
        sShell = new Shell(display);
        sShell.setText("Shell");
        sShell.setLayout(gridLayout);  // Generated
        sShell.setSize(new Point(640, 480));
        getCenterTabFolder();
    }
    
    public void updateCityList(final Session session) {
		
		Runnable r = new Runnable() {
			public void run() {
				cityList.setInput(session);
			}
		};
		sShell.getDisplay().asyncExec(r);
	}
    
    public void updateStatusBar(final StatusNotification statusNotification){
        
        Runnable r = new Runnable() {
            public void run() {
                statusBar.showNotification(statusNotification);
            }
        };
        sShell.getDisplay().asyncExec(r);
    }
    
    public void updateFieldsTab(final Village village){
        
        Runnable r = new Runnable() {
            public void run() {
                
                if(null == fields){
                   createFields();
                }
                fields.setInput(village);
            }
        };
        sShell.getDisplay().asyncExec(r);
    }
    
    private void createFields(){
        fields = new Fields(centerTabFolder, SWT.NONE);
        filedsTabItem = new TabItem(centerTabFolder, SWT.NONE);
        filedsTabItem.setControl((Composite)fields);
        filedsTabItem.setText("Fields");
        fields.setMainForm(this);        
    }
    
    public void updateTasksTab(final TaskQueue queue){
        
        Runnable r = new Runnable() {
            public void run() {
                
                if(null == tasks){
                    tasks = new TaskList(centerTabFolder, SWT.NONE);
                    tasksTabItem = new TabItem(centerTabFolder, SWT.NONE);
                    tasksTabItem.setControl((Composite)tasks);
                    tasksTabItem.setText("Tasks");
                }
                
                tasks.setInput(queue);
            }
        };
        sShell.getDisplay().asyncExec(r);
    }
    
    public void updateBuildingsTab(final Village village){
        
        Runnable r = new Runnable() {
            public void run() {
                
                if(null == buildings){
                    buildings = new Buildings(centerTabFolder, SWT.NONE);
                    buildingsTabItem = new TabItem(centerTabFolder, SWT.NONE);
                    buildingsTabItem.setControl((Composite)buildings);
                    buildingsTabItem.setText("Buildings");
                }
                
                buildings.setInput(village);
            }
        };
        sShell.getDisplay().asyncExec(r);
    }

    /**
     * This method initializes centerTabFolder	
     * 	
     * @return org.eclipse.swt.widgets.TabFolder	
     */
    private TabFolder getCenterTabFolder() {
    
        if (centerTabFolder == null) {
            try {
                GridData centerTabFolderLData = new GridData();
                centerTabFolderLData.grabExcessHorizontalSpace = true;
                centerTabFolderLData.horizontalAlignment = GridData.FILL;
                centerTabFolderLData.verticalAlignment = GridData.FILL;
                centerTabFolderLData.grabExcessVerticalSpace = true;
                centerTabFolder = new TabFolder(sShell, SWT.NONE);
                centerTabFolder.setLayoutData(centerTabFolderLData);
                {
                    GridData cityListLData = new GridData();
                    cityListLData.grabExcessVerticalSpace = true;
                    cityListLData.horizontalAlignment = GridData.FILL;
                    cityListLData.verticalAlignment = GridData.FILL;
                    cityList = new CityList(sShell, SWT.NONE);
                    ((Composite)cityList).setLayoutData(cityListLData);
                    cityList.setMainForm(this);
                }
                {
                    statusBar = new StatusBar(sShell, SWT.NONE);
                    GridData statusBarLData = new GridData();
                    statusBarLData.heightHint = 40;
                    statusBarLData.horizontalSpan = 2;
                    statusBarLData.horizontalAlignment = GridData.FILL;
                    statusBarLData.grabExcessHorizontalSpace = true;
                    statusBar.setLayoutData(statusBarLData);
                }
            }
            catch (java.lang.Throwable e) {
                // TODO: Something
            }
        }
        return centerTabFolder;
    }

	public void setUIFactory(UIFactory factory) {
		// TODO Auto-generated method stub
		
	}

	public void setSession(Session session) {
		// TODO Auto-generated method stub
		
	}

    public ImageRegistry getImageRegistry() {

        // TODO Auto-generated method stub
        return null;
    }

    public void setGameSession(GameSessionFacade gameSession) {

        // TODO Auto-generated method stub
        
    }

    public GameSessionFacade getGameSession() {

        // TODO Auto-generated method stub
        return null;
    }
}
